package com.suneee.quartz.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.suneee.core.util.StringUtils;
import com.suneee.orm.GenericDao;
import com.suneee.orm.util.WhereClauseBuilder;
import com.suneee.quartz.dao.ScheduleConfigDao;
import com.suneee.quartz.entity.ScheduleConfig;

@Repository("scheduleConfigDao")
public class ScheduleConfigDaoImpl extends GenericDao<ScheduleConfig, Integer>implements ScheduleConfigDao{

	@Override
	public ScheduleConfig getScheduleConfig(ScheduleConfig dto) {
		WhereClauseBuilder sbf = this.wrapWhereSQL(dto);
		List<ScheduleConfig> list = this.selectWhere(sbf.getSql(),sbf.getArgs());
		
		if(list != null &&  list.size() >0){
			return list.get(0);
		}else{
			return null;
		}
	}
	
	private WhereClauseBuilder wrapWhereSQL(ScheduleConfig dto){
		WhereClauseBuilder sbf = new WhereClauseBuilder();
		if(dto.getShopId() != null){
			sbf.equals("shop_id",dto.getShopId());
		}
		if(!StringUtils.isEmpty(dto.getEnterpriseCode())){
			sbf.equals("enterprise_code",dto.getEnterpriseCode());
		}
		sbf.equals("business_group", dto.getBusinessGroup());
		
		return sbf;
	}

	
}
